<extend name="Layout/application"/>

<block name="content">
    <div class="row">
        <div class="col-md-12">

            <div class="row">
                <div class="col-md-8">
                    <div class="page-header">
                        <h1>友情链接</h1>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-10">
                    <div class="panel panel-default">
                        <div class="panel-heading">友情链接</div>

                        <div class="panel-body">
                            <table class="table">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" id="all_check"></th>
                                    <th>id</th>
                                    <th>网站名称</th>
                                    <th>网站地址</th>
                                    <th>排序</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <form action="" method="post" id="form">
                                <tbody>
                                <volist name="links" id="l">
                                <tr>
                                    <td><input type="checkbox" name="delete_id[]" class="check" value="{{$l.id}}"></td>
                                    <td class="id">{{$l.id}}</td>
                                    <td class="name"><a href="{{$l.url}}">{{$l.name}}</a></td>
                                    <td class="url">{{$l.url}}</td>
                                    <input type="hidden" name="id[]" value="{{$l.id}}">
                                    <td ><input type="text" name="sort_order[]" value="{{$l.sort_order}}"></td>
                                    <td>
                                        <a href="" data-toggle="modal" data-target="#edit_link" class="edit">
                                            <span class="glyphicon glyphicon-pencil"></span>
                                        </a>
                                        <a href="{{:U('destroy',array('id'=>$l['id']))}}">
                                            <span class="glyphicon glyphicon-trash"></span>
                                        </a>
                                    </td>
                                </tr>
                                </volist>
                                </tbody>
                                </form>
                            </table>
                        </div>
                    </div>
                </div>


                <div class="col-md-2">
                    <div class="list-group">
                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category" data-toggle="modal" data-target="#create">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 新增 (add)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category" id="sort_order">
                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 排序 (sort)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category" id="destroy_checked">
                            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除 (del)
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Button trigger modal -->
    <!--<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">-->
        <!--Launch demo modal-->
    <!--</button>-->

    <!-- Modal -->
    <div class="modal fade" id="create" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="add">增加友情链接</h4>
                </div>
                <form class="form-horizontal" role="form" method="post" action="{{:U('store')}}">
                    <div class="modal-body">
                            <div class="form-group">
                                <label for="name" class="col-sm-2 control-label">网站名称</label>
                                <div class="col-sm-10">
                                    <input type="text" name="name" class="form-control" id="name" placeholder="请输入网站名称">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="url" class="col-sm-2 control-label">网站地址</label>
                                <div class="col-sm-10">
                                    <input type="text" name="url" class="form-control" id="url" placeholder="请输入网站地址">
                                </div>
                            </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">新增</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- Button trigger modal -->
    <!--<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#edit_link">-->
        <!--Launch demo modal-->
    <!--</button>-->

    <!-- Modal -->
    <div class="modal fade" id="edit_link" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">编辑友情链接</h4>
                </div>
                <form class="form-horizontal" role="form" method="post" action="{{:U('update')}}">

                        <div class="form-group">
                            <label for="edit_name" class="col-sm-2 control-label">网站名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="name" id="edit_name" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="edit_url" class="col-sm-2 control-label">网站地址</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="url" id="edit_url" placeholder="">
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">编辑</button>
                    </div>
                </form>
            </div>
        </div>
</div>


</block>
<block name="js">
    <script>
        $(function () {
            $('.edit').click(function ()
            {
                var id=  $(this).parent().siblings('.id').text();
                var name=  $(this).parent().siblings('.name').text();
                var url=  $(this).parent().siblings('.url').text();
                $('#edit_id').val(id);
                $('#edit_name').val(name);
                $('#edit_url').val(url);

            })


            $('#all_check').click(function () {
                $('.check').prop('checked',this.checked);
            })

            $('#destroy_checked').click(function () {
                var length = $('.check:checked').length;
                if(length == 0){
                    alert('你必须选中一条');
                    return false;
                }
                $('#form').attr('action',"{{:U('destroy_checked')}}").submit();

            })

            $('#sort_order').click(function () {
                $('#form').attr('action',"{{:U('sort_order')}}").submit();

            })


        })
    </script>
</block>